home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / demo / text / lines.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  2.1 KB  |  85 lines

  1. {
  2.     $Id: lines.pp,v 1.1 2000/03/09 02:49:09 alex Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1993-98 by Florian Klaempfl
  5.  
  6.     Line Counter Example
  7.  
  8.     See the file COPYING.FPC, included in this distribution,
  9.     for details about the copyright.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  
  15.  **********************************************************************}
  16. program count_lines;
  17. {
  18.   Program that counts number of Lines in a file
  19. }
  20.  
  21.   uses
  22.      dos,crt;
  23.  
  24.   type
  25.      td = array[1..10000] of byte;
  26.  
  27.   var
  28.      lines : longint;
  29.      s : searchrec;
  30.      f : file;
  31.      d : ^td;
  32. {$ifdef tp}
  33.      count : word;
  34.      i,z   : integer;
  35. {$else}
  36.      count,i,z : longint;
  37. {$endif}
  38.  
  39.   begin
  40.      lines:=0;
  41.      new(d);
  42.      if paramcount<1 then
  43.        begin
  44.           writeln('Usage: ',paramstr(0),' filename.ext [filename.ext] ...');
  45.           writeln('  Multiple File Names and Wild Cards Allowed:');
  46.           writeln('  Example: lines *.cpp stdio.h *.asm');
  47.           halt(1);
  48.        end;
  49.      for i:=1 to paramcount do
  50.        begin
  51.           findfirst(paramstr(i),archive,s);
  52.           while (doserror=0) do
  53.             begin
  54.                gotoxy(1,wherey);
  55.                write('                               ');
  56.                gotoxy(1,wherey);
  57.                write('Scanning: ',s.name);
  58.                assign(f,s.name);
  59.                reset(f,1);
  60.                while not(eof(f)) do
  61.                  begin
  62.                     blockread(f,d^,10000,count);
  63.                     for z:=1 to count do
  64.                       if d^[z]=10 then inc(lines);
  65.                  end;
  66.                close(f);
  67.                findnext(s);
  68.             end;
  69.        end;
  70.      dispose(d);
  71.      gotoxy(1,wherey);
  72.      write('                               ');
  73.      gotoxy(1,wherey);
  74.      if lines=1 then writeln('1 Line') else writeln(lines,' Lines');
  75.   end.
  76. {
  77.   $Log: lines.pp,v $
  78.   Revision 1.1  2000/03/09 02:49:09  alex
  79.   moved files
  80.  
  81.   Revision 1.2  1998/09/11 10:55:23  peter
  82.     + header+log
  83.  
  84. }
  85.